/**
 * Copyright (c) 2024 Hunan OpenValley Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef OHOS_GPURENDER_H
#define OHOS_GPURENDER_H
#include "GPURenderThread.h"
#include "napi_util.h"
#include <ace/xcomponent/native_interface_xcomponent.h>
#include <multimedia/image_framework/image_mdk_common.h>
#include <multimedia/image_framework/image_pixel_map_mdk.h>

#include <mutex>
#include <thread>
class GPURender {
public:
    static GPURender *instance;
    static GPURender *getInstance();
    void setCallback(std::shared_ptr<CallbackListener> callback);
    uint64_t getSurfaceId();
    void updateXComponentSize(int width, int height);
    void setFilter(std::shared_ptr<GPUImageFilter> filter);
    void savePixelMap(std::shared_ptr<CallbackListener> callback);
    void releaseRenderThread();
    void dumpImage(const std::string &path);
    void runOnDraw(std::function<void()> task);
    void startRenderThread(void *nativeWindow, uint64_t width, uint64_t height);
    void setOrientation(Rotation rotation, bool flipX, bool flipY);

private:
    napi_value gEnv;
    static std::once_flag onceFlag;
    std::unique_ptr<GPURenderThread> renderThread = nullptr;

private:
    GPURender();
    ~GPURender();
    GPURender(const GPURender &) = delete;
    void operator=(const GPURender &) = delete;
};

#endif // OHOS_GPURENDER_H
